package com.heima.comment.controller.v1;

import com.heima.comment.service.CommentService;
import com.heima.model.comment.dtos.CommentDTO;
import com.heima.model.comment.dtos.CommentLikeDTO;
import com.heima.model.comment.dtos.CommentSaveDTO;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.validator.ValidatorSaveComment;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author huan
 * @serial 每天一百行, 致敬未来的自己
 * @Description
 */
@RestController
@Api(value = "评论管理API", tags = "评论管理API")
@RequestMapping("/api/v1/comment")
public class CommentController {
    @Autowired
    CommentService commentSaveService;

    @PostMapping("/save")
    @ApiOperation("保存评论功能")
    public ResponseResult saveComment(@RequestBody @Validated({ValidatorSaveComment.class}) CommentSaveDTO dto) {
        return commentSaveService.saveComment(dto);
    }

    @PostMapping("/like")
    @ApiOperation("保存评论点赞")
    public ResponseResult saveCommentLike(@RequestBody CommentLikeDTO dto) {
        return commentSaveService.saveCommentLike(dto);
    }

    @PostMapping("/load")
    @ApiOperation("加载评论列表")
    public ResponseResult loadCommentList(@RequestBody CommentDTO dto) {
        return commentSaveService.loadCommentList(dto);
    }
}
